package se.lnu.axez;

/**
 * Represents 3 arbitrary float values. Provides convenient methods to read the
 * values. Instances of this class should never be used as hash keys, since
 * changes to the object which created the instance will influence the values
 * returned by the methods of this class.
 * 
 * @author stan
 * 
 */
// This class is immutable outside the package.
public final class FloatTriple {
	private final float[] backingArray;
	private final int aOffset;
	private final int bOffset;
	private final int cOffset;
	
	public static FloatTriple create(float x, float y, float z) {
		return new FloatTriple(new float[] { x, y, z}, 0, 1, 2);
	}

	FloatTriple(float[] backingArray, int aOffset, int bOffset, int cOffset) {
		this.backingArray = backingArray;
		this.aOffset = aOffset;
		this.bOffset = bOffset;
		this.cOffset = cOffset;
	}

	/**
	 * Gets first value.
	 */
	public float first() {
		return this.backingArray[this.aOffset];
	}

	/**
	 * Gets second value.
	 */
	public float second() {
		return this.backingArray[this.bOffset];
	}

	/**
	 * Gets third value.
	 */
	public float third() {
		return this.backingArray[this.cOffset];
	}
	
	/**
	 * Gets first value.
	 */
	public float a() {
		return this.first();
	}
	
	/**
	 * Gets second value.
	 */
	public float b() {
		return this.second();
	}
	
	/**
	 * Gets third value.
	 */
	public float c() {
		return this.third();
	}

	/**
	 * Gets first value.
	 */
	public float x() {
		return this.first();
	}

	/**
	 * Gets second value.
	 */
	public float y() {
		return this.second();
	}

	/**
	 * Gets third value.
	 */
	public float z() {
		return this.third();
	}

	@Override
	public String toString() {
		return "{" + this.first() + ", " + this.second() + ", " + this.third() + "}";
	}
}
